package com.baizhi.controller;

import com.baizhi.entity.Emp;
import com.baizhi.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/emps")
public class EmpController {
    @Autowired
    private EmpService es;
    @GetMapping
    public List<Emp> selectAll(String con){
        if (con!=null!="".equals(con)){
            return es.selectByCon(con);
        }
        return es.selectAll();
    }
    @GetMapping("/{id}")
    public Emp selectOne(@PathVariable("id") int id){
        return es.selectOne(id);
    }
    @DeleteMapping("/{id}")
    public void delete(@PathVariable("id") int id){
        es.delete(id);
    }
    @PutMapping
    public void update(@RequestBody Emp emp){
        es.update(emp);
    }
    @PostMapping
    public void insert(@RequestBody Emp emp){
        es.insert(emp);
    }
}
